package com.jingdianjichi.gateway.auth.entity;


import com.jingdianjichi.gateway.auth.enums.ResultCodeEnum;
import lombok.Data;

/**
 * ClassName:Result
 * Package:com.jingdianjichi.entity
 * Description:
 *
 * @Author fst
 * @Create 2024/9/26 16:09
 * @Version 1.0
 */

@Data
public class Result<T>
{
    private Boolean success;

    private Integer code;

    private String message;

    private T data;

    public static Result ok()
    {
        Result result=new Result();
        result.setSuccess(true);
        result.setCode(ResultCodeEnum.SUCCESS.getCode());
        result.setMessage(ResultCodeEnum.SUCCESS.getDesc());

        return result;
    }
    public static <T> Result ok(T data)
    {
        Result result=new Result();
        result.setSuccess(true);
        result.setCode(ResultCodeEnum.SUCCESS.getCode());
        result.setMessage(ResultCodeEnum.SUCCESS.getDesc());
        result.setData(data);

        return result;
    }

    public static Result fail()
    {
        Result result=new Result();

        result.setSuccess(false);
        result.setCode(ResultCodeEnum.FAIL.getCode());
        result.setMessage(ResultCodeEnum.FAIL.getDesc());
        return result;
    }

    public static Result fail(String message)
    {
        Result result=new Result();

        result.setSuccess(false);
        result.setCode(ResultCodeEnum.FAIL.getCode());
        result.setMessage(message);
        return result;
    }

    public static Result fail(int code, String message)
    {
        Result result=new Result();
        result.setCode(code);
        result.setMessage(message);
        return result;
    }
}
